﻿
// The Ribbon Namespace
var SBRibbon = {

    // Get DOM object properties
    _gO: function(obj, coord) {
        obj = document.getElementById(obj);
        var val = obj["offset" + coord];
        while ((obj = obj.offsetParent) != null) {
            val += obj["offset" + coord];
        }
        return val;
    },

    // Show a Gallery
    OpenGallery: function(src, trg) {
        var src1 = document.getElementById(src);
        document.getElementById(trg).style.display = (document.getElementById(trg).style.display == "none") ? "block" : "none";
        document.getElementById(trg).style.left = SBRibbon._gO(src, "Left") + "px";
        document.getElementById(trg).style.top = (SBRibbon._gO(src, "Top") + src1.offsetHeight - 1) + "px";
    },

    // Show a menu
    ShowMenu: function(src, trg) {
        document.getElementById(trg).style.display = (document.getElementById(trg).style.display == "none") ? "block" : "none";
        document.getElementById(trg).style.left = SBRibbon._gO(src.id, "Left") + "px";
        document.getElementById(trg).style.top = (SBRibbon._gO(src.id, "Top") + src.offsetHeight) + "px";
    },

    // Keep the menu opened
    KeepMenu: function(trg) {
        document.getElementById(trg).style.display = "";
        document.getElementById(trg).getAttribute("MenuOpener").className = "RibbonSmallItem_Over";
    },

    // Hide a menu
    HideMenu: function(trg) {
        document.getElementById(trg).style.display = "none";
    },

    // Register the "File Menu"
    RegisterFileMenu: function(text, container, menu, color) {
        try {
            if (color == null) {
                color = "green";
            }
            var divTag = document.createElement("div");
            divTag.id = "SBRibbon_FileMenu";
            divTag.className = "Ribbon_FileMenu Ribbon_FileMenu_" + color; // Change this classname to customize the File Menu, See CSS file
            divTag.innerHTML = text;
            divTag.setAttribute("onclick", "SBRibbon.ShowMenu(this, '" + menu + "_FileMenu')");

            document.body.appendChild(divTag);

            var temp_bar = document.getElementById(container + "_header");
            temp_bar.insertBefore(divTag, temp_bar.firstChild);

            document.getElementById("SBRibbon_FileMenu").appendChild(document.getElementById(menu + "_FileMenu"));

        } catch (e) { alert(e); }
    },

    About: function() {
        alert("SBRibbon, http://aspnetribbon.codeplex.com");
    }

};











